<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!Doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>密码修改</title>
    <link href="/static/css/common/style.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/common/user.css" rel="stylesheet" type="text/css"/>
    <script src="/static/js/jquery.js" type="text/javascript"></script>
    <link href="/static/css/common/common.css" rel="stylesheet" type="text/css"/>
    <script src="/static/js/common.js" type="text/javascript"></script>

    <style>
        table, tr, td {
            border: none;
        }

        table tr {
            height: 50px;
        }

        .noticeWrap {
            padding: 0px;
            float: none;
        }

        .noticeWrap span {
            float: none;
            line-height: normal;
        }

        .user_client p {
            margin-bottom: 0px;
            width: 100%;
            float: none;
        }
    </style>
</head>
<body id="reg">
<jsp:include page="../../themes/header.jsp"/>
<div class="w100">
    <div class="w1000">
        <div class="login_pic">
            <h1>密码修改</h1>
        </div>
        <div class="user_client">
            <div class="user_client_left">
                <form id="regform" method="post" action="#" onsubmit="return false;">
                    <table class="tab1">
                        <tr>
                            <td align="right">* 当前密码</td>
                            <td><input type="password" id="nowPwd" name="nowPwd" placeholder="当前密码"/></td>
                        </tr>
                        <tr>
                            <td align="right">* 新密码</td>
                            <td><input type="password" id="newPwd" name="newPwd" placeholder="新密码"/></td>
                        </tr>
                        <tr>
                            <td align="right">* 重复密码:</td>
                            <td><input type="password" id="reNewPwd" name="reNewPwd" placeholder="新密码"/></td>
                        </tr>
                    </table>
                    <p>
                        <span> <input type="submit" value="密码修改" class="uc_submit btn_yellow"
                                      onclick="changePwd();"> </span>
                    </p>
                </form>
            </div>
            <div class="clearer"></div>
        </div>
    </div>
    <jsp:include page="../../themes/footer.jsp"/>
</div>
<!--#include virtual="/themes/orange/footer.html"-->
</body>
<c:if test="${empty sessionScope.sysUser}">
    <script type="text/javascript">
        alert("亲爱的用户，请先登录");
        window.location.href="/loginReg/login.do";
    </script>
</c:if>
<script type="text/javascript">
    function changePwd() {
        var nowPwd = $("#nowPwd").val();
        var newPwd = $("#newPwd").val();
        var reNewPwd = $("#reNewPwd").val();
        if (nowPwd == "") {
            alert("亲爱的用户，请输入当前密码！");
            return;
        }
        if (newPwd == "") {
            alert("亲爱的用户，请输入新密码！");
            return;
        }

        if (reNewPwd == "") {
            alert("亲爱的用户，请输入重复密码！");
            return;
        }

        if (newPwd!=reNewPwd) {
            alert("两次密码不一致");
            return;
        }
        loginSubmit(nowPwd,newPwd);
    }
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            var nowPwd = $("#nowPwd").val();
            var newPwd = $("#newPwd").val();
            var reNewPwd = $("#reNewPwd").val();
            if (nowPwd == "") {
                alert("亲爱的用户，请输入当前密码！");
                return;
            }
            if (newPwd == "") {
                alert("亲爱的用户，请输入新密码！");
                return;
            }

            if (reNewPwd == "") {
                alert("亲爱的用户，请输入重复密码！");
                return;
            }

            if (newPwd!=reNewPwd) {
                alert("两次密码不一致");
                return;
            }
        }
    }
    function loginSubmit(nowPwd,newPwd){
        $.ajax({
            type: "POST",
            url: '/changePwd.do',
            data: {"nowPwd":nowPwd,"newPwd":newPwd},
            success: function(ret){
                if(ret.msg=='1'){
                    alert("恭喜你修改成功");
                    window.location.href="/index.do";
                } else {
                    alert("密码错误！");
                }
            }
        });
    }
</script>
</html>
